﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "NdbPropertyChange.h"

namespace gcmp
{
    class NdbObjectMemoryModelGroupNode;
    typedef std::function<bool(const NdbObjectMemoryModelGroupNode * pOldObjMemModel, NdbObjectMemoryModelGroupNode * pNewObjMemModel)>
        NdbCustomizedUpgrader;

    //////////////////////////////////////////////////////////////////////////
    /// \brief 类schema的变化。类的每次升级对应一个NdbClassSchemaChange对象
    class GCMP_DATABASE_EXPORT NdbClassSchemaChange
    {
    public:
        NdbClassSchemaChange() : m_version(1) { }

        NdbClassSchemaChange(UInt32 version) : m_version(version) { }

        UInt32 GetVersion() const { return m_version; }

        void AddParentClassChange(const NdbParentClassChange& parentClassChange);
        const NdbParentClassChange * GetParentClassChange() const;

        void AddPropertyChange(const NdbPropertyChangeBase& propChangeBase);
        const std::vector<const NdbPropertyChangeBase*> GetPropertyChanges(EnPropertyChangeType changeType) const;

        void AddCustomizedUpgrader(NdbCustomizedUpgrader upgrader);
        const std::vector<NdbCustomizedUpgrader>& GetCustomizedUpgraders() const;

    private:
        UInt32                                             m_version;

        std::vector<NdbAddPropertyChange>                  m_addPropertyChanges;
        std::vector<NdbDeletePropertyChange>               m_deletePropertyChanges;
        std::vector<NdbRenamePropertyChange>               m_renamePropertyChanges;
        std::vector<NdbRetypePropertyChange>               m_retypePropertyChanges;
        std::vector<NdbExchangePropertyWithAncestorChange> m_exchangePropertyWithAncestorChanges;

        std::vector<NdbParentClassChange>                  m_parentClassChange;

        std::vector<NdbCustomizedUpgrader>                 m_customizedUpgraders;
    };

    struct NdbClassSchemaChangeComparerByVersion
    {
        bool operator()(const NdbClassSchemaChange & lhs, const NdbClassSchemaChange & rhs) const
        {
            return lhs.GetVersion() < rhs.GetVersion();
        }
    };
}

